package dmir.reaction.tests;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import dmir.reaction.publico.mysql.MySQLConnection;

public class Test {
	
	static Connection conn = null;
	
	public static void main(String[] args) throws Exception {
		
		conn = MySQLConnection.getConnection("root", "xpto123", null);

		System.out.println(getNewsText("politica", 3232));
		
	}
	
	public static String getNewsText(String section, int id) throws Exception {
		
		PreparedStatement preparedStatement = conn.prepareStatement("SELECT title,subtitle,newstext,origLink FROM " + section + " WHERE id = ? ");
		preparedStatement.setInt(1, id);
			
		ResultSet resultSet = preparedStatement.executeQuery();
		
		resultSet.next();
		
		String title = resultSet.getString(1);
		String subtitle = resultSet.getString(2);
		String text = resultSet.getString(3);
		String url = resultSet.getString(4);
		
		return title.trim() + '\n' + subtitle.trim() + '\n' + text.trim() + '\n' + url.split("_")[1];
		
	}
}
